mongo_createDocument Function
Syntax
Arguments
- mongoURL_or_connectionStringCharacter
A Mongo AlphaDAO connection string (e.g. "::name::mymongodb") or the base URL for a MongoDB server (e.g. "mongodb+srv://user:pass@cluster.mongodb.net/test").
- databaseNameCharacter
The name of the MongoDB database. If using an AlphaDAO connection string, this is inferred automatically. The database will be created if it does not exist. Case sensitive.
- collectionCharacter
The name of the collection where the document will be created. The collection will be created if it does not exist.
- jsonCharacter
The JSON data defining the new document.
Returns
- resultPointer
Returns an object with the following properties:
- errorLogical
.t. if an error occurred, otherwise .f.
- errorTextCharacter
Error details if an error occurred.
- _idCharacter
The ID of the newly created document.
Description
Creates a new document in a MongoDB collection and returns the new document ID.
Example
dim p as p
p.firstName = "Fred"
p.lastName = "Smith"
dim json as c
json = json_generate(p)
dim pr as p
pr = mongo_createDocument("::name::my_mongo_connString", "myDatabase", "newCollection", json)
if pr.error = .f. then
showvar("Created document ID: " + pr._id)
else
showvar("Error: " + pr.errorText)
end ifSee Also